export default {
    state: {
        sessionCount:0,//会话的count
		newFriendCount:0,//新好友
    },
    mutations: {
		
    },
	actions: {
		// 更新会话角标提示
		updateChatBadge({
		  state,
		  dispatch
		}, action) {
		  const { type, count } = action;
		  switch (type) {
		    case 'set':
		      state.sessionCount = count;
		      break;
		    case 'add':
		      state.sessionCount += count;
		      break;
		    case 'sub':
			  if(state.sessionCount >= count){
			    state.sessionCount -= count;
			  }else{
				state.sessionCount = 0;
			  }
		      break;
		    default:
		      throw new Error('Invalid action type. Valid options are "set", "add", "subtract".');
		  }
		},
		// 更新好友角标提示
		updateFriendBadge({
		  state,
		  dispatch
		}, action) {
			console.log('进来计算了');
		  const { type, count } = action;
		  switch (type) {
		    case 'set':
		      state.newFriendCount = count;
		      break;
		    case 'add':
		      state.newFriendCount += count;
		      break;
		    case 'sub':
			  if(state.newFriendCount >= count){
				  state.newFriendCount -= count;
			  }else{
				  state.newFriendCount = 0;
			  }
		      break;
		    default:
		      throw new Error('Invalid action type. Valid options are "set", "add", "subtract".');
		  }
		  console.log(state.newFriendCount);
		}
	}
};